/*
 * p4283.cpp
 *
 *  Created on: 2013-7-21
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 105;
int dp[maxn][maxn], d[maxn], s[maxn];
int t, n;
int main()
{
	cin >> t;
	for (int cas = 1; cas <= t; cas++)
	{
		cin >> n;
		s[0] = 0;
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &d[i]);
			s[i] = s[i - 1] + d[i];
		}
		memset(dp, 0x3f3f3f3f, sizeof(dp));
		for (int i = n; i >= 1; i--)
		{
			dp[i][i] = 0;
			for (int j = i + 1; j <= n; j++)
				for (int k = 1; k <= j - i + 1; k++)
				{
					int tem = 0;
					if (i + 1 <= i + k - 1)
						tem += dp[i + 1][i + k - 1];
					if (i + k <= j)
						tem += dp[i + k][j];
					tem+=k*(s[j]-s[i+k-1])+(k-1)*d[i];
					dp[i][j]=min(dp[i][j],tem);
				}

		}
		printf("Case #%d: %d\n",cas,dp[1][n]);
	}
	return 0;
}
